#include "HelloWorldScene.h"

USING_NS_CC;

CCScene* HelloWorld::scene()
{
    // 'scene' is an autorelease object
    CCScene *scene = CCScene::create();
    
    // 'layer' is an autorelease object
    HelloWorld *layer = HelloWorld::create();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Guardian2.plist");
    
    return true;
}

void HelloWorld::onEnter() {
    CCLayer::onEnter();
    
    CCSprite *ren = CCSprite::createWithSpriteFrameName("Guardian_run_0001.png");
    this->setPosition(ccp(100, 100));
    
//    CCSprite *gebo = CCSprite::createWithSpriteFrameName("Guardian_Arm.png");
//    gebo->setAnchorPoint(ccp(0.682, 0.726));
//    gebo->setPosition(ccp(107.0, 65.0));
//    gebo->setRotation(30);
//    ren->addChild(gebo);
//    
    this->addChild(ren);
//
//    CCArray *frames = CCArray::create(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("Guardian_run_0001.png"),
//                                      CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("Guardian_run_0002.png"),
//                                      CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("Guardian_run_0003.png"),
//                                      CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("Guardian_run_0004.png"),
//                                      CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("Guardian_run_0005.png"),
//                                      CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("Guardian_run_0006.png"),
//                                      CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("Guardian_run_0007.png"),
//                                      NULL);
//    
//    CCAnimation *donghua = CCAnimation::createWithSpriteFrames(frames);
//    donghua->setDelayPerUnit(0.1);
//    donghua->setLoops(-1);
//    
//    CCAnimate *action = CCAnimate::create(donghua);
    CCMoveTo *a = CCMoveTo::create(3.0f, ccp(0, 0));
//    CCSpawn *sp = CCSpawn::create(action, moveto, NULL);
    
    ren->runAction(a);
    
//    gebo->runAction(CCRotateBy::create(0.2, -30));
}


void HelloWorld::menuCloseCallback(CCObject* pSender)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
	CCMessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");
#else
    CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    exit(0);
#endif
#endif
}
